//
//  GYXWelcomeView.swift
//  GYXWeibo
//
//  Created by Twisal on 2017/3/7.
//  Copyright © 2017年 Twisal. All rights reserved.
//

import UIKit
import SDWebImage

class GYXWelcomeView: UIView {
    @IBOutlet weak var avatarView: UIImageView!
    @IBOutlet weak var welcomeLabel: UILabel!
    @IBOutlet weak var bottomCons: NSLayoutConstraint!

    
    /// 创建视图的类方法
    ///
    /// - Returns: 欢迎视图
    class func welcomeView() -> GYXWelcomeView {
        let nib = UINib(nibName: "GYXWelcomeView", bundle: nil)
        let v = nib.instantiate(withOwner: self, options: nil)[0] as! GYXWelcomeView
        v.frame = UIScreen.main.bounds
        return v
    }
    
    
    override func awakeFromNib() {
         super.awakeFromNib()
        guard let urlString = GYXNetworkManager.shared.userAccount.avatar_large
        else {
            return
        }
        //  设置圆形图片
        
        avatarView.cz_setImage(urlString: urlString, placeholderImage: UIImage(named: "avatar_default_big"), isAvatar: true)
    }
    
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        
        layoutIfNeeded()
        bottomCons.constant = bounds.height - 200
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
            self.layoutIfNeeded()
        }) { (_) in
            UIView.animate(withDuration: 1.0, animations: { 
                self.welcomeLabel.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
        }
    }
}
